#pragma once
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
using namespace std ;

#include "Quadrant.h"
#include "Missile.h"

enum playerState { IDLE, MOVE, ATTACK, DOCK } ;

class Player 
{
private:
	Missile* m_Missile ;

	//current quadrant player is in
	int m_QuadPosX ;
	int m_QuadPosY ;

	//current sector player is in
	int m_PosX ;
	int m_PosY ;

	int m_LastPosX ;
	int m_LastPosY ;

	//player's target sector (x, y)
	int m_TargetX ;
	int m_TargetY ;

	//current state of player
	int m_state ;

	int m_energy ;
	int m_shields ;
	int m_missiles ;

	bool m_dead ;
public:
	Player( ) ;
	~Player( ) ;

	//returns the current state
	int GetState( ) {return m_state ;}

	//returns current player's quadrant
	int GetQuadX( ) {return m_QuadPosX ;}
	int GetQuadY( ) {return m_QuadPosY ;}

	//returns current player's sector
	int GetPosX( ) {return m_PosX ;}
	int GetPosY( ) {return m_PosY ;}

	int GetMissileCount( ) {return m_missiles ;}

	int GetEnergy( ) {return m_energy ;}

	int GetShields( ) {return m_shields ;}

	//moves the player one sector in x or y direction
	void Move( Quadrant* currQuad ) ;

	void ShiftBack( ) ;

	void MoveMissile( Quadrant* currQuad ) { m_Missile->Move( currQuad ) ; }

	//warps player to new quadrant
	void Warp( int x, int y ) ;

	//sets the state of the player
	void SetState( int state ) {m_state = state ;}

	//sets the x and y target
	void SetTarget( int x, int y ) ;

	//increase/decrease player's shields
	void ChangeShields( int amount ) { m_shields += amount ; }

	void DamagePlayer( int enemyHealth, int distance ) ;

	void Dock( ) ;

	//get position of the target sector
	int GetTargetX( ) { return m_TargetX ; }
	int GetTargetY( ) { return m_TargetY ; }

	//fires missile to the specified target sector
	void FireMissile( int x, int y ) ;

	//decrease energy from ship
	void FireBlasters( int energy ) { m_energy -= energy ; }

	//delete missile when it collides with a unit
	void DestroyMissile( ) {delete m_Missile ;}

	//checks if it collided with a non-empty sector
	bool Collision( Quadrant* currQuad ) ;

	//checks if missile is destroyed (NULL)
	bool MissileDestroyed( ) { return m_Missile == NULL ; }

	bool IsDead( ) {return m_dead ;}

	Missile* GetMissile( ) {return m_Missile ;}
} ;